﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using DataAccessEntLib;
using System.Xml;

public partial class GoogleMapControl : System.Web.UI.UserControl
{
    BO.Ad bo = new BO.Ad();
    BLL.AdMagnager bll = new BLL.AdMagnager();

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdID"] != null)
            {
                string strURL = string.Empty, Address = string.Empty, State = string.Empty, Country = string.Empty;
                IDataReader dr;
                bo.AdID = Convert.ToInt32(Session["AdID"].ToString());
                dr = bll.SelectAdLocation_AdID(bo);
                if (dr != null)
                {
                    if (dr.Read())
                    {
                        if (dr["LandMark"] != DBNull.Value)
                            Address = dr["LandMark"].ToString();

                        if (dr["State"] != DBNull.Value)
                            State = dr["State"].ToString();

                        if (dr["Country"] != DBNull.Value)
                            Country = dr["Country"].ToString();
                    }
                }
                dr.Close();

                strURL = "http://maps.googleapis.com/maps/api/geocode/xml?address=";
                strURL = strURL + Address + "+" + State + "+" + Country + "&sensor=true";
                XmlDocument xDoc = new XmlDocument();
                //xDoc.Load("http://maps.googleapis.com/maps/api/geocode/xml?address=621+Arya mohalla + nangloi+New DElhi&sensor=true");
                xDoc.Load(strURL);
                var lat = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat").InnerText;
                var longitude = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText;

                Hidden1.Value = lat;
                Hidden2.Value = longitude;

                Session["AdID"] = null;
            }
        }
        catch (Exception ex)
        {
        }
    }
}